<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/react/16.8.4/umd/react.development.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/react-dom/16.8.4/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/prop-types/15.8.1/prop-types.js"></script>
  </head>
  <body>
    <div id="test"></div>
    <script type="text/babel">
      // 定义组件
      function Demo(props) {
        console.log(this); // undefined
        console.log(props); // undefined
        let { name, age } = props;
        return (
          <div>
            <h1>函数组件--{name}</h1>
            <div>22--{age}</div>
          </div>
        );
      }
      let info = {
        name: "zs",
        age: 2,
      };
      // 类型限制
      Demo.propTypes = {
        name: PropTypes.string,
        age: PropTypes.number.isRequired,
      };
      Demo.defaultProps = {
        name: "zhangsan",
      };
      // 渲染组件
      ReactDOM.render(
        // 开启严格模式
        <React.StrictMode>
          <Demo {...info} />
        </React.StrictMode>,
        document.getElementById("test")
      );
    </script>
  </body>
</html>
